#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(int i = a; i <= b; i++)
#define For2(i,a,b) for(int i = a; i >= b; i--)
using namespace std;
const int N = 2e5 + 1;
int n,a[N];
bool flag[N];
void work() {
    cin >> n;
    For(i,1,n) cin >> a[i];
    int k = (1 << n);
    ll ans = -1;
    if (n <= 15) {
        while (k >= 0) {
            ll sum = 0;
            int tmp = k,cnt = 0;
            while (tmp > 0) {
                flag[++cnt] = tmp % 2;
                tmp /= 2;
            }
            For (i,1,n) {
                For (j,1,i-1) {
                    if (flag[i] == flag[j] && a[i] == a[j]) {
                        sum += a[j];
                        break;
                    }
                }
            }
            ans = max(ans,sum);
            k--;
        }
        cout << ans << endl;
    }
}

int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int _ = 1; cin >> _;
    while (_--) work();
    return 0;
}


